using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Text;
using System.Windows.Forms;

namespace YT.Controls
{
    public partial class LableTextBox : UserControl
    {

        private System.Windows.Forms.BorderStyle m_BorderStyle = System.Windows.Forms.BorderStyle.Fixed3D  ;

        private string m_value = "";
        private string m_strLableText = string.Empty;

        private int m_iMaxLength = 0;

        public delegate void ValueChangedEventHandler(object sender, EventArgs e);
        public event ValueChangedEventHandler ValueChanged;
        protected virtual void OnValueChanged(EventArgs e)
        {
            if (ValueChanged != null)
            {
                ValueChanged(this, e);
            }
        }

        public new System.Windows.Forms.BorderStyle  BorderStyle
        {
            get
            {
                return m_BorderStyle;
            }
            set
            {
                m_BorderStyle = value;
                this.txtItem.BorderStyle = value;
                SetSize();
               }
        }

        public string Value
        {
            get
            {
                return m_value;
            }
            set
            {
                this.txtItem.Text = value;
                this.txtItem.Refresh();
                m_value = value ;
            }
        }

        public string LableText
        {
            get
            {
                return m_strLableText;
            }
            set
            {
                this.lblItem.Text = value;
                this.lblItem.Refresh();
                m_strLableText = value;
            }
        }

        public int MaxLength
        {
            get
            {
                return m_iMaxLength;
            }
            set
            {
                this.txtItem.MaxLength = value;
                m_iMaxLength = value;
            }
        }

        public LableTextBox()
        {
            InitializeComponent();
        }

        public override string Text
        {
            get
            {
                return this.txtItem.Text; 
                
            }
            set
            {
                this.txtItem.Text = value;
                this.txtItem.Refresh(); 
            }
        }

        private void LableTextBox_Load(object sender, EventArgs e)
        {
            SetSize();
        }
        private void LableTextBox_Resize(object sender, EventArgs e)
        {
            SetSize();
        }
        private void LableTextBox_Enter(object sender, System.EventArgs e)
        {
            if (ComFunc.IsNumeric(this.Text.Trim()))
                this.txtItem.SelectAll();
        }

        private void SetSize()
        {
            this.lblItem.Location = new Point(0, 0);
            this.txtItem.Location = new Point(0, this.lblItem.Height);
        }

        private void txtItem_TextChanged(object sender, EventArgs e)
        {
            m_value = this.txtItem.Text; 
            this.OnValueChanged(e); 
        }

        private void txtItem_KeyPress(object sender, KeyPressEventArgs e)
        {
            if (e.KeyChar == '.')
            {
                //MessageBox.Show("ok"); 
            }
        }

    }
}
